package com.bridgeintelligent.tag.combination.controller;

import com.bridgeintelligent.tag.combination.entity.CombinationPage;
import com.bridgeintelligent.tag.combination.entity.Result;
import com.bridgeintelligent.tag.combination.exception.CombinationException;
import com.bridgeintelligent.tag.combination.model.CombinationStopModel;
import com.bridgeintelligent.tag.combination.model.CombinationStopQueryModel;
import com.bridgeintelligent.tag.combination.pojo.Combination;
import com.bridgeintelligent.tag.combination.service.ICombinationStopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @description
 * @author: grp 2021-03-03 21:28
 **/
@Api(tags = "组合标签失效")
@RestController
@AllArgsConstructor
@Validated
@Slf4j
@RequestMapping("api/combinationStop")
public class CombinationStopController {

    ICombinationStopService combinationStopService;

    @ApiOperation(value = "关联组合标签列表", notes = "组合标签停用")
    @GetMapping("list")
    public Result list(@ModelAttribute @Valid CombinationStopQueryModel model) {
        model.setPageNumber(model.getPageNumber() == null ? 1 : model.getPageNumber());
        model.setPageSize(model.getPageSize() == null ? 10 : model.getPageSize());
        CombinationPage<Combination> page = combinationStopService.list(model);
        return new Result(0,page);
    }

    @ApiOperation(value = "批量/全选", notes = "组合标签停用")
    @PostMapping("/batch")
    public Result batch(@RequestBody CombinationStopModel model) {
        try{
            combinationStopService.delete(model);
        }catch (CombinationException e) {
            return new Result(e.getCode(),"操作失败");
        }
        return new Result(0);
    }
}
